// pages/doing/doingProgress.js
const httpUtils = require('../../utils/httpUtils')
const ui = require('../../utils/ui')
const systemInfo = wx.getWindowInfo();
const bottomInset = Math.abs(systemInfo.safeArea.bottom - systemInfo.windowHeight);

//按钮颜色
var button_color = "#FF4B55";
//按钮是否可以点击
var button_enable = true;
Page({
  data: {
    order_no: '',
    task_no: '',
    task_title: '任务标题',
    task_time: '0小时',
    task_surplus: 0,
    task_end_time: '0天结束',
    task_price: '+0元/次',
    button_status: '待领取',
    steps: []
  },
  onLoad(options) {
    this.setData({
      scrollViewBottomInset: bottomInset+64,
      bottomInset: bottomInset,
      order_no: options.orderNo
    });
    this.requestTask();
    this.requestProgress();
  },
  //请求任务订单数据
  requestTask() {
    let obj = {
      method: 'GET',
      url: '/task-order/' + this.data.order_no,
      showLoading: true,
      data: {}
    }
    httpUtils.request(obj).then(res => {
      //判断状态
      if (res.data.taskStatus == "待领取") {
        button_color = "#FF4B55";
        button_enable = false;
      } else if (res.data.taskStatus == "待提交") {
        button_color = "#4BBE97";
        button_enable = false;
      } else if (res.data.taskStatus == "已拒绝") {
        button_color = "#A2A2A2";
        button_enable = false;
      } else {
        button_color = "#A2A2A2";
        button_enable = true;
      }
      this.setData({
        task_no: res.data.taskNo,
        task_title: res.data.taskTitle,
        task_time: res.data.bidSubmitDurationTimeDisplay,
        task_surplus: res.data.leftBidTime,
        task_end_time: res.data.endTimeDisplay,
        task_price: res.data.rewardAmountDisplay,
        button_status: res.data.statusLabel,
        button_enable: button_enable,
        button_color: button_color
      })
    }).catch(err => {
      console.log(err)
    }); 
  },
  //请求进程数据
  requestProgress() {
    let obj = {
      method: 'GET',
      url: '/task-order/' + this.data.order_no + '/process',
      data: {}
    }
    httpUtils.request(obj).then(res => {
      this.setData({
        steps: res.data
      })
    }).catch(err => {
      console.log(err)
    });
  },
  //查看提交结果
  actionShowSubmitResult() {
    wx.navigateTo({
      url: '/pages/doing/doingSubmitResult?orderNo='+this.data.order_no,
    })
  },
  //任务详情
  actionTaskDetail() {
    wx.navigateTo({
      url: '/pages/task/taskDetail?taskNo='+this.data.task_no,
    })
  },
  //点击任务按钮
  actionTask() {
    wx.navigateTo({
      url: '/pages/task/taskSubmit?taskNo='+this.data.task_no,
    })
  },
})